package com.sailing.lianxi.inner;


/**
 * 成员内部类型demo
 * @author Administrator
 *
 */
public class MemberInnerDemo {

	public static void main(String[] args) {
		//创建成员内部类的对象-方式一通过Outter对象来创建
		Outter outter = new Outter(10.02D,"WG");
//		Outter.Inner innerObj = outter.new Inner("wg_inner");
//		innerObj.drawShape();
		
		//创建成员内部类的对象-方式二:
		Outter.Inner inner = outter.getInnerInstance("wg_inner");
		inner.drawShape();
	}
}

class Outter{//外部类
	private double radius = 0;
    public static int count =1;
    private String name;
    private Inner inner = null;
    public Outter(double radius,String name){
    	this.radius = radius;
    	this.name = name;
    	//getInnerInstance(name).drawShape();//外部类访问内部类属性，方法，必须先创建内部类的对象，在进行访问。
    }
    
    public Inner getInnerInstance(String param) {
    	if(null == inner) {
    		inner = new Inner(param+"_inner");
    	}
    	return inner;
    }
    
    
    class Inner{//内部类
    	private String name;
    	public Inner(String name) {
    		this.name = name;
    	}
    	
    	public void drawShape() {
    		System.out.println("访问外部类private属性："+radius);
    		System.out.println("访问外部类static属性："+count);
    		System.out.println("访问内部类和外部类同名属性:"+name);
    		System.out.println("访问外部类和内部类同名属性:"+Outter.this.name); //外部类.this.成员变量|外部类.this.成员方法
    	}
    }
}
